{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Run upon export from spreadsheet"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total entries: 2542\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "from astroquery.mast import Catalogs\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "\n",
    "tces_file = '/mnt/tess/labels/tois.csv'\n",
    "ext_data_file = '/mnt/tess/labels/ext_mast_data.csv'\n",
    "\n",
    "\n",
    "tce_table = pd.read_csv(tces_file, header=0, low_memory=False)\n",
    "tce_table['tic_id'] = tce_table['TIC']\n",
    "tce_table['Duration'] = tce_table['Transit Duration Value']\n",
    "tce_table['Period'] = tce_table['Orbital Period Value']\n",
    "tce_table['RA'] = tce_table['TIC Right Ascension']\n",
    "tce_table['Sectors'] = tce_table['Sectors'].apply(lambda v: len(v.split(' ')))\n",
    "tce_table['Transit_Depth'] = tce_table['Transit Depth Value']\n",
    "tce_table['Dec'] = tce_table['TIC Declination']\n",
    "tce_table['teff'] = tce_table['Effective Temperature Value']\n",
    "tce_table['SN'] = tce_table['Signal-to-noise']\n",
    "tce_table['Qingress'] = 0.0\n",
    "tce_table['Tmag'] = tce_table['TMag Value']\n",
    "tce_table['logg'] = tce_table['Surface Gravity Value']\n",
    "tce_table['Epoc'] = tce_table['Epoch Value']\n",
    "tce_table['star_rad'] = tce_table['Star Radius Value']\n",
    "# G = 6.67e-8 in cgs\n",
    "tce_table['star_mass'] = ((10 ** tce_table['logg']) * (tce_table['star_rad'] ** 2)) / 6.67e-8\n",
    "tce_table = tce_table.set_index('tic_id')\n",
    "# tce_table = tce_table.drop(columns=['Unnamed: 0'])\n",
    "\n",
    "tce_table['Duration'] /= 24.0\n",
    "\n",
    "tce_table\n",
    "\n",
    "# # Drop some common invalid examples.\n",
    "# # Orbits falling inside the star\n",
    "# tce_table = tce_table[~tce_table.Ilabel]\n",
    "# # Excessively large durations\n",
    "# tce_table = tce_table[tce_table.Duration < 0.9 * tce_table.Period]\n",
    "\n",
    "joined_table = tce_table\n",
    "\n",
    "# ext_table = pd.read_csv(ext_data_file, header=0, low_memory=False).set_index('tic_id')\n",
    "# joined_table = joined_table.join(ext_table, on='tic_id', how='left')\n",
    "\n",
    "# joined_table = joined_table[\n",
    "#     joined_table['objType'].isnull()\n",
    "#     | (joined_table['objType'] == 'STAR')\n",
    "# ]\n",
    "\n",
    "joined_table = joined_table.reset_index()[[\n",
    "    'tic_id', 'RA', 'Dec', 'Tmag', 'Epoc', 'Period', 'Duration',\n",
    "    'Transit_Depth', 'Sectors', 'star_rad', 'star_mass', 'teff',\n",
    "    'logg', 'SN', 'Qingress'\n",
    "]]\n",
    "\n",
    "\n",
    "disps = ['E', 'J', 'N', 'S', 'B']\n",
    "\n",
    "for d in disps:\n",
    "    joined_table[f'disp_{d}'] = 0\n",
    "\n",
    "joined_table = joined_table.set_index('tic_id')\n",
    "print(f'Total entries: {len(joined_table)}')\n",
    "\n",
    "joined_table.to_csv('/mnt/tess/astronet/tces-toi.csv')\n",
    "\n",
    "# python astronet/preprocess/generate_input_records.py --input_tce_csv_file=/mnt/tess/astronet/tces-toi.csv --tess_data_dir=/mnt/tess/lc --output_dir=/mnt/tess/astronet/tfrecords-toi --num_shards=1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Source Pipeline</th>\n",
       "      <th>TIC</th>\n",
       "      <th>Full TOI ID</th>\n",
       "      <th>TOI Disposition</th>\n",
       "      <th>EXOFOP Disposition</th>\n",
       "      <th>TIC Right Ascension</th>\n",
       "      <th>TIC Declination</th>\n",
       "      <th>TMag Value</th>\n",
       "      <th>TMag Uncertainty</th>\n",
       "      <th>VMag Value</th>\n",
       "      <th>VMag Uncertainty</th>\n",
       "      <th>Epoch Value</th>\n",
       "      <th>Epoch Error</th>\n",
       "      <th>Orbital Period Value</th>\n",
       "      <th>Orbital Period Error</th>\n",
       "      <th>Transit Duration Value</th>\n",
       "      <th>Transit Duration Error</th>\n",
       "      <th>Transit Depth Value</th>\n",
       "      <th>Transit Depth Error</th>\n",
       "      <th>Sectors</th>\n",
       "      <th>Public Comment</th>\n",
       "      <th>Surface Gravity Value</th>\n",
       "      <th>Surface Gravity Uncertainty</th>\n",
       "      <th>Signal ID</th>\n",
       "      <th>Star Radius Value</th>\n",
       "      <th>Star Radius Error</th>\n",
       "      <th>Planet Radius Value</th>\n",
       "      <th>Planet Radius Error</th>\n",
       "      <th>Planet Equilibrium Temperature (K) Value</th>\n",
       "      <th>Effective Temperature Value</th>\n",
       "      <th>Effective Temperature Uncertainty</th>\n",
       "      <th>Effective Stellar Flux Value</th>\n",
       "      <th>Signal-to-noise</th>\n",
       "      <th>Centroid Offset</th>\n",
       "      <th>TFOP Master</th>\n",
       "      <th>TFOP SG1a</th>\n",
       "      <th>TFOP SG1b</th>\n",
       "      <th>TFOP SG2</th>\n",
       "      <th>TFOP SG3</th>\n",
       "      <th>TFOP SG4</th>\n",
       "      <th>TFOP SG5</th>\n",
       "      <th>Alerted</th>\n",
       "      <th>Updated</th>\n",
       "      <th>Duration</th>\n",
       "      <th>Period</th>\n",
       "      <th>RA</th>\n",
       "      <th>Transit_Depth</th>\n",
       "      <th>Dec</th>\n",
       "      <th>teff</th>\n",
       "      <th>SN</th>\n",
       "      <th>Qingress</th>\n",
       "      <th>Tmag</th>\n",
       "      <th>logg</th>\n",
       "      <th>Epoc</th>\n",
       "      <th>star_rad</th>\n",
       "      <th>star_mass</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>tic_id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>176860064</th>\n",
       "      <td>spoc</td>\n",
       "      <td>176860064</td>\n",
       "      <td>1457.01</td>\n",
       "      <td>PC</td>\n",
       "      <td>APC</td>\n",
       "      <td>354.836680</td>\n",
       "      <td>45.719897</td>\n",
       "      <td>7.1140</td>\n",
       "      <td>0.006000</td>\n",
       "      <td>7.617</td>\n",
       "      <td>0.023</td>\n",
       "      <td>1766.359365</td>\n",
       "      <td>0.001300</td>\n",
       "      <td>6.375556</td>\n",
       "      <td>0.000700</td>\n",
       "      <td>2.784942</td>\n",
       "      <td>0.204000</td>\n",
       "      <td>2638.408383</td>\n",
       "      <td>40.55020</td>\n",
       "      <td>1</td>\n",
       "      <td>No information on the star; V-shaped</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1545.000000</td>\n",
       "      <td>6393.0</td>\n",
       "      <td>280.600</td>\n",
       "      <td>947.389000</td>\n",
       "      <td>35.813244</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2019-12-05 16:42:06+0000</td>\n",
       "      <td>2019-12-05 16:42:06+0000</td>\n",
       "      <td>0.116039</td>\n",
       "      <td>6.375556</td>\n",
       "      <td>354.836680</td>\n",
       "      <td>2638.408383</td>\n",
       "      <td>45.719897</td>\n",
       "      <td>6393.0</td>\n",
       "      <td>35.813244</td>\n",
       "      <td>0.0</td>\n",
       "      <td>7.1140</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1766.359365</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>236887394</th>\n",
       "      <td>spoc</td>\n",
       "      <td>236887394</td>\n",
       "      <td>1465.01</td>\n",
       "      <td>KP</td>\n",
       "      <td>KP</td>\n",
       "      <td>303.381740</td>\n",
       "      <td>65.162081</td>\n",
       "      <td>11.8478</td>\n",
       "      <td>0.006100</td>\n",
       "      <td>12.692</td>\n",
       "      <td>0.103</td>\n",
       "      <td>1766.006734</td>\n",
       "      <td>0.000080</td>\n",
       "      <td>1.420023</td>\n",
       "      <td>0.000001</td>\n",
       "      <td>1.623014</td>\n",
       "      <td>0.009436</td>\n",
       "      <td>23593.258233</td>\n",
       "      <td>89.22266</td>\n",
       "      <td>4</td>\n",
       "      <td>Qatar-1 b</td>\n",
       "      <td>4.57248</td>\n",
       "      <td>0.082846</td>\n",
       "      <td>1</td>\n",
       "      <td>0.768108</td>\n",
       "      <td>0.045256</td>\n",
       "      <td>12.293303</td>\n",
       "      <td>0.726365</td>\n",
       "      <td>1251.952037</td>\n",
       "      <td>4910.0</td>\n",
       "      <td>108.354</td>\n",
       "      <td>580.592960</td>\n",
       "      <td>280.148770</td>\n",
       "      <td>False</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>2019-12-05 16:42:06+0000</td>\n",
       "      <td>2020-09-11 14:14:29+0000</td>\n",
       "      <td>0.067626</td>\n",
       "      <td>1.420023</td>\n",
       "      <td>303.381740</td>\n",
       "      <td>23593.258233</td>\n",
       "      <td>65.162081</td>\n",
       "      <td>4910.0</td>\n",
       "      <td>280.148770</td>\n",
       "      <td>0.0</td>\n",
       "      <td>11.8478</td>\n",
       "      <td>4.57248</td>\n",
       "      <td>1766.006734</td>\n",
       "      <td>0.768108</td>\n",
       "      <td>3.305208e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>427654774</th>\n",
       "      <td>spoc</td>\n",
       "      <td>427654774</td>\n",
       "      <td>1474.01</td>\n",
       "      <td>PC</td>\n",
       "      <td>FP</td>\n",
       "      <td>349.287339</td>\n",
       "      <td>70.190021</td>\n",
       "      <td>14.1431</td>\n",
       "      <td>0.007508</td>\n",
       "      <td>16.502</td>\n",
       "      <td>0.252</td>\n",
       "      <td>1765.042474</td>\n",
       "      <td>0.003388</td>\n",
       "      <td>5.222621</td>\n",
       "      <td>0.001436</td>\n",
       "      <td>4.693629</td>\n",
       "      <td>0.613360</td>\n",
       "      <td>15867.992018</td>\n",
       "      <td>2007.71600</td>\n",
       "      <td>2</td>\n",
       "      <td>3-sigma centroid offset towards another star.</td>\n",
       "      <td>4.95337</td>\n",
       "      <td>0.008643</td>\n",
       "      <td>1</td>\n",
       "      <td>0.275946</td>\n",
       "      <td>0.008483</td>\n",
       "      <td>3.721602</td>\n",
       "      <td>0.381201</td>\n",
       "      <td>329.650849</td>\n",
       "      <td>3453.0</td>\n",
       "      <td>157.000</td>\n",
       "      <td>2.790858</td>\n",
       "      <td>8.069622</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2019-12-05 16:42:06+0000</td>\n",
       "      <td>2019-12-05 16:42:06+0000</td>\n",
       "      <td>0.195568</td>\n",
       "      <td>5.222621</td>\n",
       "      <td>349.287339</td>\n",
       "      <td>15867.992018</td>\n",
       "      <td>70.190021</td>\n",
       "      <td>3453.0</td>\n",
       "      <td>8.069622</td>\n",
       "      <td>0.0</td>\n",
       "      <td>14.1431</td>\n",
       "      <td>4.95337</td>\n",
       "      <td>1765.042474</td>\n",
       "      <td>0.275946</td>\n",
       "      <td>1.025398e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237086564</th>\n",
       "      <td>spoc</td>\n",
       "      <td>237086564</td>\n",
       "      <td>1466.01</td>\n",
       "      <td>PC</td>\n",
       "      <td>PC</td>\n",
       "      <td>307.395886</td>\n",
       "      <td>61.550433</td>\n",
       "      <td>11.0278</td>\n",
       "      <td>0.006000</td>\n",
       "      <td>12.189</td>\n",
       "      <td>0.069</td>\n",
       "      <td>1766.253229</td>\n",
       "      <td>0.001272</td>\n",
       "      <td>1.871892</td>\n",
       "      <td>0.000022</td>\n",
       "      <td>1.644789</td>\n",
       "      <td>0.260366</td>\n",
       "      <td>1031.773654</td>\n",
       "      <td>75.49385</td>\n",
       "      <td>2</td>\n",
       "      <td>potential L1 candidate</td>\n",
       "      <td>4.50790</td>\n",
       "      <td>0.110712</td>\n",
       "      <td>1</td>\n",
       "      <td>0.749646</td>\n",
       "      <td>0.071322</td>\n",
       "      <td>2.366370</td>\n",
       "      <td>1.968143</td>\n",
       "      <td>997.392351</td>\n",
       "      <td>4201.0</td>\n",
       "      <td>125.587</td>\n",
       "      <td>233.875718</td>\n",
       "      <td>12.584560</td>\n",
       "      <td>False</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2019-12-05 16:42:06+0000</td>\n",
       "      <td>2020-09-23 11:19:07+0000</td>\n",
       "      <td>0.068533</td>\n",
       "      <td>1.871892</td>\n",
       "      <td>307.395886</td>\n",
       "      <td>1031.773654</td>\n",
       "      <td>61.550433</td>\n",
       "      <td>4201.0</td>\n",
       "      <td>12.584560</td>\n",
       "      <td>0.0</td>\n",
       "      <td>11.0278</td>\n",
       "      <td>4.50790</td>\n",
       "      <td>1766.253229</td>\n",
       "      <td>0.749646</td>\n",
       "      <td>2.713230e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240968774</th>\n",
       "      <td>spoc</td>\n",
       "      <td>240968774</td>\n",
       "      <td>1467.01</td>\n",
       "      <td>PC</td>\n",
       "      <td>PC</td>\n",
       "      <td>19.113929</td>\n",
       "      <td>49.233780</td>\n",
       "      <td>10.5977</td>\n",
       "      <td>0.007301</td>\n",
       "      <td>12.293</td>\n",
       "      <td>0.017</td>\n",
       "      <td>1766.983728</td>\n",
       "      <td>0.002812</td>\n",
       "      <td>5.973384</td>\n",
       "      <td>0.001413</td>\n",
       "      <td>1.605698</td>\n",
       "      <td>0.753235</td>\n",
       "      <td>1373.411277</td>\n",
       "      <td>166.74307</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4.74552</td>\n",
       "      <td>0.007707</td>\n",
       "      <td>1</td>\n",
       "      <td>0.490737</td>\n",
       "      <td>0.014515</td>\n",
       "      <td>1.827003</td>\n",
       "      <td>2.407974</td>\n",
       "      <td>525.913556</td>\n",
       "      <td>3834.0</td>\n",
       "      <td>157.000</td>\n",
       "      <td>18.079169</td>\n",
       "      <td>8.569228</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2019-12-05 16:42:06+0000</td>\n",
       "      <td>2019-12-05 16:42:06+0000</td>\n",
       "      <td>0.066904</td>\n",
       "      <td>5.973384</td>\n",
       "      <td>19.113929</td>\n",
       "      <td>1373.411277</td>\n",
       "      <td>49.233780</td>\n",
       "      <td>3834.0</td>\n",
       "      <td>8.569228</td>\n",
       "      <td>0.0</td>\n",
       "      <td>10.5977</td>\n",
       "      <td>4.74552</td>\n",
       "      <td>1766.983728</td>\n",
       "      <td>0.490737</td>\n",
       "      <td>2.009517e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>126572546</th>\n",
       "      <td>qlp</td>\n",
       "      <td>126572546</td>\n",
       "      <td>2527.01</td>\n",
       "      <td>PC</td>\n",
       "      <td>NaN</td>\n",
       "      <td>136.653389</td>\n",
       "      <td>-50.480484</td>\n",
       "      <td>11.1670</td>\n",
       "      <td>0.032000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1564.942827</td>\n",
       "      <td>0.003241</td>\n",
       "      <td>2.302134</td>\n",
       "      <td>0.000373</td>\n",
       "      <td>3.776000</td>\n",
       "      <td>0.310000</td>\n",
       "      <td>1140.000000</td>\n",
       "      <td>1.05888</td>\n",
       "      <td>2</td>\n",
       "      <td>possibly synchronized with variability; CTOI f...</td>\n",
       "      <td>3.54000</td>\n",
       "      <td>0.110000</td>\n",
       "      <td>1</td>\n",
       "      <td>3.450000</td>\n",
       "      <td>0.390000</td>\n",
       "      <td>11.951500</td>\n",
       "      <td>1.389960</td>\n",
       "      <td>2278.000000</td>\n",
       "      <td>6919.0</td>\n",
       "      <td>258.900</td>\n",
       "      <td>4476.820000</td>\n",
       "      <td>16.000000</td>\n",
       "      <td>False</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2021-03-02 22:57:47+0000</td>\n",
       "      <td>2021-03-02 17:51:17+0000</td>\n",
       "      <td>0.157333</td>\n",
       "      <td>2.302134</td>\n",
       "      <td>136.653389</td>\n",
       "      <td>1140.000000</td>\n",
       "      <td>-50.480484</td>\n",
       "      <td>6919.0</td>\n",
       "      <td>16.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>11.1670</td>\n",
       "      <td>3.54000</td>\n",
       "      <td>1564.942827</td>\n",
       "      <td>3.450000</td>\n",
       "      <td>6.187459e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>380836882</th>\n",
       "      <td>qlp</td>\n",
       "      <td>380836882</td>\n",
       "      <td>2526.01</td>\n",
       "      <td>PC</td>\n",
       "      <td>NaN</td>\n",
       "      <td>270.134854</td>\n",
       "      <td>-65.613847</td>\n",
       "      <td>11.0590</td>\n",
       "      <td>0.006000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1676.866770</td>\n",
       "      <td>0.001360</td>\n",
       "      <td>8.011524</td>\n",
       "      <td>0.000923</td>\n",
       "      <td>5.170000</td>\n",
       "      <td>0.444000</td>\n",
       "      <td>7810.000000</td>\n",
       "      <td>3.34366</td>\n",
       "      <td>1</td>\n",
       "      <td>odd-even likely from detrending transit at beg...</td>\n",
       "      <td>4.25000</td>\n",
       "      <td>0.080000</td>\n",
       "      <td>1</td>\n",
       "      <td>1.290000</td>\n",
       "      <td>0.070000</td>\n",
       "      <td>11.589300</td>\n",
       "      <td>0.651645</td>\n",
       "      <td>1222.000000</td>\n",
       "      <td>5923.0</td>\n",
       "      <td>139.100</td>\n",
       "      <td>370.573000</td>\n",
       "      <td>57.000000</td>\n",
       "      <td>False</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2021-03-02 22:57:47+0000</td>\n",
       "      <td>2021-03-02 17:50:45+0000</td>\n",
       "      <td>0.215417</td>\n",
       "      <td>8.011524</td>\n",
       "      <td>270.134854</td>\n",
       "      <td>7810.000000</td>\n",
       "      <td>-65.613847</td>\n",
       "      <td>5923.0</td>\n",
       "      <td>57.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>11.0590</td>\n",
       "      <td>4.25000</td>\n",
       "      <td>1676.866770</td>\n",
       "      <td>1.290000</td>\n",
       "      <td>4.436634e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149601126</th>\n",
       "      <td>qlp</td>\n",
       "      <td>149601126</td>\n",
       "      <td>2525.01</td>\n",
       "      <td>PC</td>\n",
       "      <td>NaN</td>\n",
       "      <td>86.850783</td>\n",
       "      <td>-60.521408</td>\n",
       "      <td>13.4010</td>\n",
       "      <td>0.006000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2174.013303</td>\n",
       "      <td>0.006910</td>\n",
       "      <td>23.349908</td>\n",
       "      <td>0.000289</td>\n",
       "      <td>4.523000</td>\n",
       "      <td>0.577000</td>\n",
       "      <td>6090.000000</td>\n",
       "      <td>6.99742</td>\n",
       "      <td>16</td>\n",
       "      <td>potential multi; CTOI from Planet Hunters</td>\n",
       "      <td>4.51000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0.820000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6.636840</td>\n",
       "      <td>NaN</td>\n",
       "      <td>556.000000</td>\n",
       "      <td>4944.0</td>\n",
       "      <td>122.000</td>\n",
       "      <td>15.958200</td>\n",
       "      <td>15.000000</td>\n",
       "      <td>False</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2021-03-02 22:57:47+0000</td>\n",
       "      <td>2021-03-02 17:37:55+0000</td>\n",
       "      <td>0.188458</td>\n",
       "      <td>23.349908</td>\n",
       "      <td>86.850783</td>\n",
       "      <td>6090.000000</td>\n",
       "      <td>-60.521408</td>\n",
       "      <td>4944.0</td>\n",
       "      <td>15.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>13.4010</td>\n",
       "      <td>4.51000</td>\n",
       "      <td>2174.013303</td>\n",
       "      <td>0.820000</td>\n",
       "      <td>3.262135e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149601126</th>\n",
       "      <td>qlp</td>\n",
       "      <td>149601126</td>\n",
       "      <td>2525.02</td>\n",
       "      <td>PC</td>\n",
       "      <td>NaN</td>\n",
       "      <td>86.850783</td>\n",
       "      <td>-60.521408</td>\n",
       "      <td>13.4010</td>\n",
       "      <td>0.006000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2123.257222</td>\n",
       "      <td>0.006354</td>\n",
       "      <td>49.242380</td>\n",
       "      <td>0.000541</td>\n",
       "      <td>6.930000</td>\n",
       "      <td>1.202000</td>\n",
       "      <td>14290.000000</td>\n",
       "      <td>1601.01000</td>\n",
       "      <td>16</td>\n",
       "      <td>potential multi; CTOI from Planet Hunters</td>\n",
       "      <td>4.51000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>0.820000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10.342100</td>\n",
       "      <td>NaN</td>\n",
       "      <td>603.000000</td>\n",
       "      <td>4944.0</td>\n",
       "      <td>122.000</td>\n",
       "      <td>21.981400</td>\n",
       "      <td>1000.000000</td>\n",
       "      <td>False</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2021-03-02 22:57:47+0000</td>\n",
       "      <td>2021-03-02 17:37:38+0000</td>\n",
       "      <td>0.288750</td>\n",
       "      <td>49.242380</td>\n",
       "      <td>86.850783</td>\n",
       "      <td>14290.000000</td>\n",
       "      <td>-60.521408</td>\n",
       "      <td>4944.0</td>\n",
       "      <td>1000.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>13.4010</td>\n",
       "      <td>4.51000</td>\n",
       "      <td>2123.257222</td>\n",
       "      <td>0.820000</td>\n",
       "      <td>3.262135e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>169249234</th>\n",
       "      <td>qlp</td>\n",
       "      <td>169249234</td>\n",
       "      <td>2524.01</td>\n",
       "      <td>PC</td>\n",
       "      <td>NaN</td>\n",
       "      <td>160.886800</td>\n",
       "      <td>-1.912719</td>\n",
       "      <td>12.1770</td>\n",
       "      <td>0.007000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1550.143136</td>\n",
       "      <td>0.001464</td>\n",
       "      <td>14.384843</td>\n",
       "      <td>0.000765</td>\n",
       "      <td>4.198000</td>\n",
       "      <td>0.298000</td>\n",
       "      <td>11360.000000</td>\n",
       "      <td>4.12581</td>\n",
       "      <td>1</td>\n",
       "      <td>period may be half due to data gap; CTOI from ...</td>\n",
       "      <td>4.30000</td>\n",
       "      <td>0.080000</td>\n",
       "      <td>1</td>\n",
       "      <td>1.190000</td>\n",
       "      <td>0.060000</td>\n",
       "      <td>13.055400</td>\n",
       "      <td>0.760853</td>\n",
       "      <td>774.000000</td>\n",
       "      <td>5758.3</td>\n",
       "      <td>135.600</td>\n",
       "      <td>59.658400</td>\n",
       "      <td>34.000000</td>\n",
       "      <td>False</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2021-03-02 22:57:47+0000</td>\n",
       "      <td>2021-03-02 17:36:53+0000</td>\n",
       "      <td>0.174917</td>\n",
       "      <td>14.384843</td>\n",
       "      <td>160.886800</td>\n",
       "      <td>11360.000000</td>\n",
       "      <td>-1.912719</td>\n",
       "      <td>5758.3</td>\n",
       "      <td>34.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>12.1770</td>\n",
       "      <td>4.30000</td>\n",
       "      <td>1550.143136</td>\n",
       "      <td>1.190000</td>\n",
       "      <td>4.236118e+11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2542 rows × 56 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          Source Pipeline        TIC  Full TOI ID TOI Disposition  \\\n",
       "tic_id                                                              \n",
       "176860064            spoc  176860064      1457.01              PC   \n",
       "236887394            spoc  236887394      1465.01              KP   \n",
       "427654774            spoc  427654774      1474.01              PC   \n",
       "237086564            spoc  237086564      1466.01              PC   \n",
       "240968774            spoc  240968774      1467.01              PC   \n",
       "...                   ...        ...          ...             ...   \n",
       "126572546             qlp  126572546      2527.01              PC   \n",
       "380836882             qlp  380836882      2526.01              PC   \n",
       "149601126             qlp  149601126      2525.01              PC   \n",
       "149601126             qlp  149601126      2525.02              PC   \n",
       "169249234             qlp  169249234      2524.01              PC   \n",
       "\n",
       "          EXOFOP Disposition  TIC Right Ascension  TIC Declination  \\\n",
       "tic_id                                                               \n",
       "176860064                APC           354.836680        45.719897   \n",
       "236887394                 KP           303.381740        65.162081   \n",
       "427654774                 FP           349.287339        70.190021   \n",
       "237086564                 PC           307.395886        61.550433   \n",
       "240968774                 PC            19.113929        49.233780   \n",
       "...                      ...                  ...              ...   \n",
       "126572546                NaN           136.653389       -50.480484   \n",
       "380836882                NaN           270.134854       -65.613847   \n",
       "149601126                NaN            86.850783       -60.521408   \n",
       "149601126                NaN            86.850783       -60.521408   \n",
       "169249234                NaN           160.886800        -1.912719   \n",
       "\n",
       "           TMag Value  TMag Uncertainty  VMag Value  VMag Uncertainty  \\\n",
       "tic_id                                                                  \n",
       "176860064      7.1140          0.006000       7.617             0.023   \n",
       "236887394     11.8478          0.006100      12.692             0.103   \n",
       "427654774     14.1431          0.007508      16.502             0.252   \n",
       "237086564     11.0278          0.006000      12.189             0.069   \n",
       "240968774     10.5977          0.007301      12.293             0.017   \n",
       "...               ...               ...         ...               ...   \n",
       "126572546     11.1670          0.032000         NaN               NaN   \n",
       "380836882     11.0590          0.006000         NaN               NaN   \n",
       "149601126     13.4010          0.006000         NaN               NaN   \n",
       "149601126     13.4010          0.006000         NaN               NaN   \n",
       "169249234     12.1770          0.007000         NaN               NaN   \n",
       "\n",
       "           Epoch Value  Epoch Error  Orbital Period Value  \\\n",
       "tic_id                                                      \n",
       "176860064  1766.359365     0.001300              6.375556   \n",
       "236887394  1766.006734     0.000080              1.420023   \n",
       "427654774  1765.042474     0.003388              5.222621   \n",
       "237086564  1766.253229     0.001272              1.871892   \n",
       "240968774  1766.983728     0.002812              5.973384   \n",
       "...                ...          ...                   ...   \n",
       "126572546  1564.942827     0.003241              2.302134   \n",
       "380836882  1676.866770     0.001360              8.011524   \n",
       "149601126  2174.013303     0.006910             23.349908   \n",
       "149601126  2123.257222     0.006354             49.242380   \n",
       "169249234  1550.143136     0.001464             14.384843   \n",
       "\n",
       "           Orbital Period Error  Transit Duration Value  \\\n",
       "tic_id                                                    \n",
       "176860064              0.000700                2.784942   \n",
       "236887394              0.000001                1.623014   \n",
       "427654774              0.001436                4.693629   \n",
       "237086564              0.000022                1.644789   \n",
       "240968774              0.001413                1.605698   \n",
       "...                         ...                     ...   \n",
       "126572546              0.000373                3.776000   \n",
       "380836882              0.000923                5.170000   \n",
       "149601126              0.000289                4.523000   \n",
       "149601126              0.000541                6.930000   \n",
       "169249234              0.000765                4.198000   \n",
       "\n",
       "           Transit Duration Error  Transit Depth Value  Transit Depth Error  \\\n",
       "tic_id                                                                        \n",
       "176860064                0.204000          2638.408383             40.55020   \n",
       "236887394                0.009436         23593.258233             89.22266   \n",
       "427654774                0.613360         15867.992018           2007.71600   \n",
       "237086564                0.260366          1031.773654             75.49385   \n",
       "240968774                0.753235          1373.411277            166.74307   \n",
       "...                           ...                  ...                  ...   \n",
       "126572546                0.310000          1140.000000              1.05888   \n",
       "380836882                0.444000          7810.000000              3.34366   \n",
       "149601126                0.577000          6090.000000              6.99742   \n",
       "149601126                1.202000         14290.000000           1601.01000   \n",
       "169249234                0.298000         11360.000000              4.12581   \n",
       "\n",
       "           Sectors                                     Public Comment  \\\n",
       "tic_id                                                                  \n",
       "176860064        1               No information on the star; V-shaped   \n",
       "236887394        4                                          Qatar-1 b   \n",
       "427654774        2      3-sigma centroid offset towards another star.   \n",
       "237086564        2                             potential L1 candidate   \n",
       "240968774        1                                                NaN   \n",
       "...            ...                                                ...   \n",
       "126572546        2  possibly synchronized with variability; CTOI f...   \n",
       "380836882        1  odd-even likely from detrending transit at beg...   \n",
       "149601126       16          potential multi; CTOI from Planet Hunters   \n",
       "149601126       16          potential multi; CTOI from Planet Hunters   \n",
       "169249234        1  period may be half due to data gap; CTOI from ...   \n",
       "\n",
       "           Surface Gravity Value  Surface Gravity Uncertainty  Signal ID  \\\n",
       "tic_id                                                                     \n",
       "176860064                    NaN                          NaN          1   \n",
       "236887394                4.57248                     0.082846          1   \n",
       "427654774                4.95337                     0.008643          1   \n",
       "237086564                4.50790                     0.110712          1   \n",
       "240968774                4.74552                     0.007707          1   \n",
       "...                          ...                          ...        ...   \n",
       "126572546                3.54000                     0.110000          1   \n",
       "380836882                4.25000                     0.080000          1   \n",
       "149601126                4.51000                          NaN          1   \n",
       "149601126                4.51000                          NaN          2   \n",
       "169249234                4.30000                     0.080000          1   \n",
       "\n",
       "           Star Radius Value  Star Radius Error  Planet Radius Value  \\\n",
       "tic_id                                                                 \n",
       "176860064                NaN                NaN                  NaN   \n",
       "236887394           0.768108           0.045256            12.293303   \n",
       "427654774           0.275946           0.008483             3.721602   \n",
       "237086564           0.749646           0.071322             2.366370   \n",
       "240968774           0.490737           0.014515             1.827003   \n",
       "...                      ...                ...                  ...   \n",
       "126572546           3.450000           0.390000            11.951500   \n",
       "380836882           1.290000           0.070000            11.589300   \n",
       "149601126           0.820000                NaN             6.636840   \n",
       "149601126           0.820000                NaN            10.342100   \n",
       "169249234           1.190000           0.060000            13.055400   \n",
       "\n",
       "           Planet Radius Error  Planet Equilibrium Temperature (K) Value  \\\n",
       "tic_id                                                                     \n",
       "176860064                  NaN                               1545.000000   \n",
       "236887394             0.726365                               1251.952037   \n",
       "427654774             0.381201                                329.650849   \n",
       "237086564             1.968143                                997.392351   \n",
       "240968774             2.407974                                525.913556   \n",
       "...                        ...                                       ...   \n",
       "126572546             1.389960                               2278.000000   \n",
       "380836882             0.651645                               1222.000000   \n",
       "149601126                  NaN                                556.000000   \n",
       "149601126                  NaN                                603.000000   \n",
       "169249234             0.760853                                774.000000   \n",
       "\n",
       "           Effective Temperature Value  Effective Temperature Uncertainty  \\\n",
       "tic_id                                                                      \n",
       "176860064                       6393.0                            280.600   \n",
       "236887394                       4910.0                            108.354   \n",
       "427654774                       3453.0                            157.000   \n",
       "237086564                       4201.0                            125.587   \n",
       "240968774                       3834.0                            157.000   \n",
       "...                                ...                                ...   \n",
       "126572546                       6919.0                            258.900   \n",
       "380836882                       5923.0                            139.100   \n",
       "149601126                       4944.0                            122.000   \n",
       "149601126                       4944.0                            122.000   \n",
       "169249234                       5758.3                            135.600   \n",
       "\n",
       "           Effective Stellar Flux Value  Signal-to-noise Centroid Offset  \\\n",
       "tic_id                                                                     \n",
       "176860064                    947.389000        35.813244             NaN   \n",
       "236887394                    580.592960       280.148770           False   \n",
       "427654774                      2.790858         8.069622             NaN   \n",
       "237086564                    233.875718        12.584560           False   \n",
       "240968774                     18.079169         8.569228             NaN   \n",
       "...                                 ...              ...             ...   \n",
       "126572546                   4476.820000        16.000000           False   \n",
       "380836882                    370.573000        57.000000           False   \n",
       "149601126                     15.958200        15.000000           False   \n",
       "149601126                     21.981400      1000.000000           False   \n",
       "169249234                     59.658400        34.000000           False   \n",
       "\n",
       "           TFOP Master  TFOP SG1a  TFOP SG1b  TFOP SG2  TFOP SG3  TFOP SG4  \\\n",
       "tic_id                                                                       \n",
       "176860064          3.0        4.0        3.0       3.0       4.0       4.0   \n",
       "236887394          5.0        5.0        5.0       5.0       5.0       5.0   \n",
       "427654774          2.0        4.0        2.0       2.0       4.0       4.0   \n",
       "237086564          1.0        4.0        1.0       1.0       4.0       4.0   \n",
       "240968774          3.0        4.0        3.0       3.0       4.0       4.0   \n",
       "...                ...        ...        ...       ...       ...       ...   \n",
       "126572546          3.0        4.0        3.0       3.0       4.0       4.0   \n",
       "380836882          3.0        4.0        3.0       3.0       4.0       4.0   \n",
       "149601126          3.0        4.0        3.0       3.0       4.0       4.0   \n",
       "149601126          3.0        4.0        3.0       3.0       4.0       4.0   \n",
       "169249234          3.0        4.0        3.0       3.0       4.0       4.0   \n",
       "\n",
       "           TFOP SG5                   Alerted                   Updated  \\\n",
       "tic_id                                                                    \n",
       "176860064       4.0  2019-12-05 16:42:06+0000  2019-12-05 16:42:06+0000   \n",
       "236887394       5.0  2019-12-05 16:42:06+0000  2020-09-11 14:14:29+0000   \n",
       "427654774       4.0  2019-12-05 16:42:06+0000  2019-12-05 16:42:06+0000   \n",
       "237086564       4.0  2019-12-05 16:42:06+0000  2020-09-23 11:19:07+0000   \n",
       "240968774       4.0  2019-12-05 16:42:06+0000  2019-12-05 16:42:06+0000   \n",
       "...             ...                       ...                       ...   \n",
       "126572546       4.0  2021-03-02 22:57:47+0000  2021-03-02 17:51:17+0000   \n",
       "380836882       4.0  2021-03-02 22:57:47+0000  2021-03-02 17:50:45+0000   \n",
       "149601126       4.0  2021-03-02 22:57:47+0000  2021-03-02 17:37:55+0000   \n",
       "149601126       4.0  2021-03-02 22:57:47+0000  2021-03-02 17:37:38+0000   \n",
       "169249234       4.0  2021-03-02 22:57:47+0000  2021-03-02 17:36:53+0000   \n",
       "\n",
       "           Duration     Period          RA  Transit_Depth        Dec    teff  \\\n",
       "tic_id                                                                         \n",
       "176860064  0.116039   6.375556  354.836680    2638.408383  45.719897  6393.0   \n",
       "236887394  0.067626   1.420023  303.381740   23593.258233  65.162081  4910.0   \n",
       "427654774  0.195568   5.222621  349.287339   15867.992018  70.190021  3453.0   \n",
       "237086564  0.068533   1.871892  307.395886    1031.773654  61.550433  4201.0   \n",
       "240968774  0.066904   5.973384   19.113929    1373.411277  49.233780  3834.0   \n",
       "...             ...        ...         ...            ...        ...     ...   \n",
       "126572546  0.157333   2.302134  136.653389    1140.000000 -50.480484  6919.0   \n",
       "380836882  0.215417   8.011524  270.134854    7810.000000 -65.613847  5923.0   \n",
       "149601126  0.188458  23.349908   86.850783    6090.000000 -60.521408  4944.0   \n",
       "149601126  0.288750  49.242380   86.850783   14290.000000 -60.521408  4944.0   \n",
       "169249234  0.174917  14.384843  160.886800   11360.000000  -1.912719  5758.3   \n",
       "\n",
       "                    SN  Qingress     Tmag     logg         Epoc  star_rad  \\\n",
       "tic_id                                                                      \n",
       "176860064    35.813244       0.0   7.1140      NaN  1766.359365       NaN   \n",
       "236887394   280.148770       0.0  11.8478  4.57248  1766.006734  0.768108   \n",
       "427654774     8.069622       0.0  14.1431  4.95337  1765.042474  0.275946   \n",
       "237086564    12.584560       0.0  11.0278  4.50790  1766.253229  0.749646   \n",
       "240968774     8.569228       0.0  10.5977  4.74552  1766.983728  0.490737   \n",
       "...                ...       ...      ...      ...          ...       ...   \n",
       "126572546    16.000000       0.0  11.1670  3.54000  1564.942827  3.450000   \n",
       "380836882    57.000000       0.0  11.0590  4.25000  1676.866770  1.290000   \n",
       "149601126    15.000000       0.0  13.4010  4.51000  2174.013303  0.820000   \n",
       "149601126  1000.000000       0.0  13.4010  4.51000  2123.257222  0.820000   \n",
       "169249234    34.000000       0.0  12.1770  4.30000  1550.143136  1.190000   \n",
       "\n",
       "              star_mass  \n",
       "tic_id                   \n",
       "176860064           NaN  \n",
       "236887394  3.305208e+11  \n",
       "427654774  1.025398e+11  \n",
       "237086564  2.713230e+11  \n",
       "240968774  2.009517e+11  \n",
       "...                 ...  \n",
       "126572546  6.187459e+11  \n",
       "380836882  4.436634e+11  \n",
       "149601126  3.262135e+11  \n",
       "149601126  3.262135e+11  \n",
       "169249234  4.236118e+11  \n",
       "\n",
       "[2542 rows x 56 columns]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tce_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>RA</th>\n",
       "      <th>Dec</th>\n",
       "      <th>Tmag</th>\n",
       "      <th>Epoc</th>\n",
       "      <th>Period</th>\n",
       "      <th>Duration</th>\n",
       "      <th>Transit_Depth</th>\n",
       "      <th>Sectors</th>\n",
       "      <th>star_rad</th>\n",
       "      <th>star_mass</th>\n",
       "      <th>teff</th>\n",
       "      <th>logg</th>\n",
       "      <th>SN</th>\n",
       "      <th>Qingress</th>\n",
       "      <th>disp_E</th>\n",
       "      <th>disp_J</th>\n",
       "      <th>disp_N</th>\n",
       "      <th>disp_S</th>\n",
       "      <th>disp_B</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>tic_id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>248391319</th>\n",
       "      <td>19.626777</td>\n",
       "      <td>-0.056509</td>\n",
       "      <td>12.2478</td>\n",
       "      <td>2116.583003</td>\n",
       "      <td>0.798947</td>\n",
       "      <td>0.048400</td>\n",
       "      <td>2303.819305</td>\n",
       "      <td>1</td>\n",
       "      <td>0.864137</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4785.0</td>\n",
       "      <td>4.45252</td>\n",
       "      <td>9.777322</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13023738</th>\n",
       "      <td>347.084793</td>\n",
       "      <td>-29.590320</td>\n",
       "      <td>12.2520</td>\n",
       "      <td>2104.872320</td>\n",
       "      <td>8.063500</td>\n",
       "      <td>0.141500</td>\n",
       "      <td>5180.000000</td>\n",
       "      <td>2</td>\n",
       "      <td>1.710000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5657.0</td>\n",
       "      <td>3.97000</td>\n",
       "      <td>22.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>219778329</th>\n",
       "      <td>263.851951</td>\n",
       "      <td>64.380452</td>\n",
       "      <td>8.1529</td>\n",
       "      <td>1742.874702</td>\n",
       "      <td>177.219004</td>\n",
       "      <td>0.232082</td>\n",
       "      <td>295.150196</td>\n",
       "      <td>12</td>\n",
       "      <td>1.150250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5809.0</td>\n",
       "      <td>4.33351</td>\n",
       "      <td>8.084739</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61988212</th>\n",
       "      <td>178.074472</td>\n",
       "      <td>-47.583402</td>\n",
       "      <td>14.2000</td>\n",
       "      <td>1569.455416</td>\n",
       "      <td>0.555255</td>\n",
       "      <td>0.067585</td>\n",
       "      <td>23416.400387</td>\n",
       "      <td>1</td>\n",
       "      <td>1.061680</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5591.0</td>\n",
       "      <td>4.38111</td>\n",
       "      <td>16.535254</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>346929661</th>\n",
       "      <td>0.977583</td>\n",
       "      <td>59.334778</td>\n",
       "      <td>10.1980</td>\n",
       "      <td>1770.164830</td>\n",
       "      <td>12.013000</td>\n",
       "      <td>0.170875</td>\n",
       "      <td>820.000000</td>\n",
       "      <td>1</td>\n",
       "      <td>1.230000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6178.0</td>\n",
       "      <td>4.33000</td>\n",
       "      <td>12.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   RA        Dec     Tmag         Epoc      Period  Duration  \\\n",
       "tic_id                                                                         \n",
       "248391319   19.626777  -0.056509  12.2478  2116.583003    0.798947  0.048400   \n",
       "13023738   347.084793 -29.590320  12.2520  2104.872320    8.063500  0.141500   \n",
       "219778329  263.851951  64.380452   8.1529  1742.874702  177.219004  0.232082   \n",
       "61988212   178.074472 -47.583402  14.2000  1569.455416    0.555255  0.067585   \n",
       "346929661    0.977583  59.334778  10.1980  1770.164830   12.013000  0.170875   \n",
       "\n",
       "           Transit_Depth  Sectors  star_rad  star_mass    teff     logg  \\\n",
       "tic_id                                                                    \n",
       "248391319    2303.819305        1  0.864137        NaN  4785.0  4.45252   \n",
       "13023738     5180.000000        2  1.710000        NaN  5657.0  3.97000   \n",
       "219778329     295.150196       12  1.150250        NaN  5809.0  4.33351   \n",
       "61988212    23416.400387        1  1.061680        NaN  5591.0  4.38111   \n",
       "346929661     820.000000        1  1.230000        NaN  6178.0  4.33000   \n",
       "\n",
       "                  SN  Qingress  disp_E  disp_J  disp_N  disp_S  disp_B  \n",
       "tic_id                                                                  \n",
       "248391319   9.777322       0.0       0       0       0       0       0  \n",
       "13023738   22.000000       0.0       0       0       0       0       0  \n",
       "219778329   8.084739       0.0       0       0       0       0       0  \n",
       "61988212   16.535254       0.0       0       0       0       0       0  \n",
       "346929661  12.000000       0.0       0       0       0       0       0  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.set_option('display.max_columns', None)\n",
    "joined_table.sample(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Run once"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def load_tces_old():\n",
    "    tceold = pd.read_csv('/mnt/tess/astronet/tces.csv', header=0).set_index('tic_id')\n",
    "\n",
    "    # Only keep the max sectors read.\n",
    "    maxsect = tceold.groupby('tic_id')['Sectors'].max()\n",
    "    tceold = tceold.join(maxsect, on='tic_id', how='right', rsuffix='_max')\n",
    "    tceold = tceold[tceold.Sectors == tceold.Sectors_max]\n",
    "\n",
    "    # Then keep the max row ID.\n",
    "    maxrowid = tceold.groupby('tic_id')['row_id'].max()\n",
    "    tceold = tceold.join(maxrowid, on='tic_id', how='right', rsuffix='_max')\n",
    "    tceold = tceold[tceold.row_id == tceold.row_id_max]\n",
    "\n",
    "    return tceold\n",
    "\n",
    "def generate_tce_bls_instar():\n",
    "    tcenew = pd.read_csv('/mnt/tess/labels/tce_bls_instar.csv', header=0).set_index('tic_id')\n",
    "    tceold = load_tces_old()\n",
    "    tcenorth = pd.read_csv('/mnt/tess/labels/tce_north_instar.csv', header=0).set_index('tic_id')\n",
    "\n",
    "    # Copy from old data where it's missing from the new.\n",
    "    alltce = tcenew.join(tceold, how='outer', on='tic_id', rsuffix='_old')\n",
    "    alltce = alltce.set_index('tic_id')\n",
    "\n",
    "    alltce = alltce.drop(columns=['row_id'])\n",
    "\n",
    "    def fillna(df, col_name):\n",
    "        df.loc[df[col_name].isna(), col_name] = df.loc[df[col_name].isna(), col_name + '_old']\n",
    "\n",
    "    fillna(alltce, 'toi_id')\n",
    "    fillna(alltce, 'Disposition')\n",
    "    fillna(alltce, 'RA')\n",
    "    fillna(alltce, 'Dec')\n",
    "    fillna(alltce, 'Tmag')\n",
    "    fillna(alltce, 'Epoc')\n",
    "    fillna(alltce, 'Period')\n",
    "    fillna(alltce, 'Duration')\n",
    "    fillna(alltce, 'Transit_Depth')\n",
    "    fillna(alltce, 'Sectors')\n",
    "    fillna(alltce, 'camera')\n",
    "    fillna(alltce, 'ccd')\n",
    "    fillna(alltce, 'star_rad')\n",
    "    fillna(alltce, 'star_mass')\n",
    "    fillna(alltce, 'teff')\n",
    "    fillna(alltce, 'logg')\n",
    "    fillna(alltce, 'SN')\n",
    "    fillna(alltce, 'Qingress')\n",
    "\n",
    "    alltce = alltce.drop(columns=[c for c in alltce.columns if c.endswith('_old')])\n",
    "    \n",
    "    alltce = alltce.append(tcenorth)\n",
    "    \n",
    "    alltce['Ilabel'] = alltce['Ilabel'].fillna(False)\n",
    "\n",
    "    alltce.to_csv('/mnt/tess/labels/tce_bls_instar+old.csv')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
